
import 'package:lib_bt/bean/BleBeanInterface.dart';
import 'package:lib_bt/listener/CheckBleSupportInterface.dart';
import 'package:lib_bt/send/SendInterface.dart';

import 'UUIDConfig.dart';
import 'ColorSendImpl.dart';
import 'BleBean.dart';

///color系列蓝牙兼容检测
class ColorBleSupportImpl implements CheckBleSupportInterface {
  static List<List> supportList = [];

  ColorBleSupportImpl() {
    int count = 255;
    for (int i = 2; i <= count; i++) {
      supportList.add([1, 0x54, 0x42, 0x44, i]);
    }
  }

  @override
  BleBean? isSupport(BleBeanInterface bean) {
    BleBean colorBleBean = BleBean(bean:bean);
    List matchData = [];
    for (var l in supportList) {
      matchData = CheckBleSupportInterface.getMatchData(bean.bytes, l);
      if (matchData.isNotEmpty) {
        break;
      }
    }
    if (matchData.isEmpty) {
      return null;
    } else {
      colorBleBean.bytes = matchData;
      return colorBleBean;
    }
  }

  @override
  SendInterface? getSendInterface(BleBeanInterface bean) {
    var b = isSupport(bean);
    if (b != null) {
      return ColorSendImpl(b.address);
    } else {
      return null;
    }
  }

  @override
  String getUUIDInfo() {
    return UUIDConfig.instance.getUUIDJson();
  }

  @override
  String getSupportName() {
    return "color 设备";
  }
}
